str[x:] returns a substring starting at index x
def for_loop3(str, x):
result = 0
for i in str[x:]:
if i == 'a':
result += 1
return result
Function Call | Return Value | |||
---|---|---|---|---|
for_loop3('athenian', 1) | → | |||
for_loop3('apples', 2) | → | |||
for_loop3('hello', 3) | → | |||
for_loop3('alphabet', 0) | → | |||
for_loop3('aaaaa', 3) | → | |||
for_loop3('aaaaa', 4) | → | |||
for_loop3('aaaaa', 5) | → |
Experiment with this code on Gitpod.io